package huoye.shops.utils;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import com.codeideology.android.log.LogUtils;

import java.util.Date;

import huoye.shops.huoye.user.model.User;


/**
 * Created by user on 2017/8/18.
 */

public class ViewUtils {

    public static final String TYPE_INVITE_IS_COACH = "TYPE_INVITE_IS_COACH";
    public static final String TYPE_INVITE_CENCEL = "TYPE_INVITE_CENCEL";




    public static void showUser(User user, Context context,
                                ImageView ivHeader, TextView tvUserName, ImageView ivMark) {
        /*if (user != null && Util.isOnMainThread() && context != null) {
            Glide.with(context.getApplicationContext())
                    .load(user.getHeaderImage())
                    .dontAnimate()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .placeholder(R.mipmap.ic_load_fail)
                    .error(R.mipmap.ic_load_fail_head)
                    .into(ivHeader);

            tvUserName.setText(user.getUsername());

            if(ivMark != null){
                //标识 0:普通用户 1:官方号
                if(user.getType() == MARK_TYPE){
                    ivMark.setVisibility(View.VISIBLE);
                }else {
                    ivMark.setVisibility(View.GONE);
                }
            }

        }*/

    }



    /**
     * 两个时间相差距离多少天多少小时多少分多少秒
     * @param one
     * @param two
     * @return String 返回值为：xx天xx小时xx分xx秒
     */
    public static String getDistanceTime(Date one, Date two) {

        long day = 0;
        long hour = 0;
        long min = 0;
        long sec = 0;
        try {

            long time1 = one.getTime();
            long time2 = two.getTime();
            long diff ;
            if(time1<time2) {
                diff = time2 - time1;
            } else {
                diff = time1 - time2;
            }
            day = diff / (24 * 60 * 60 * 1000);
            hour = (diff / (60 * 60 * 1000) - day * 24);
            min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
            sec = (diff/1000-day*24*60*60-hour*60*60-min*60);
        } catch (Exception e) {
            e.printStackTrace();
            LogUtils.d("test", e.getMessage());
        }

       if(day == 0 && hour == 0 && min == 0) {
           return sec + "秒";
       } else if(day == 0 && hour == 0 ) {
           return min + "分" + sec + "秒";
       } else if(day == 0 ) {
           return hour + "小时" + min + "分" + sec + "秒";
       } else {
           return day + "天" + hour + "小时" + min + "分" + sec + "秒";
       }
    }




    /**
     * 两个时间相差距离多少天多少小时多少分
     * @param one
     * @param two
     * @return String 返回值为：xx天xx小时xx分
     */
    public static String getDistanceTimeNoSec(Date one, Date two) {
        long day = 0;
        long hour = 0;
        long min = 0;
        try {
            long time1 = one.getTime();
            long time2 = two.getTime();
            long diff ;
            if(time1<time2) {
                diff = time2 - time1;
            } else {
                diff = time1 - time2;
            }
            day = diff / (24 * 60 * 60 * 1000);
            hour = (diff / (60 * 60 * 1000) - day * 24);
            min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
        } catch (Exception e) {
            e.printStackTrace();
            LogUtils.d("test", e.getMessage());
        }

       if(day == 0 && hour == 0 ) {
            return min + "分" ;
        } else if(day == 0 ) {
            return hour + "小时" + min + "分" ;
        } else {
            return day + "天" + hour + "小时" + min + "分";
        }
    }

    /**
     * 两个时间相差距离多少天
     * @param one
     * @param two
     * @return String 返回值为：xx天
     */
    public static long getDistanceTimeDay(Date one, Date two) {
        long day = 0;

        try {
            long time1 = one.getTime();
            long time2 = two.getTime();
            long diff ;
            if(time1<time2) {
                diff = time2 - time1;
            } else {
                diff = time1 - time2;
            }
            day = diff / (24 * 60 * 60 * 1000);
        } catch (Exception e) {
            e.printStackTrace();

        }
       return day ;

    }




    /**
     * 两个时间相差距离多少小时
     * @param one
     * @param two
     * @return String 返回值为：xx天xx小时xx分
     */
    public static long getDistanceTimeHour(Date one, Date two) {
        long day = 0;
        long hour = 0;
        try {
            long time1 = one.getTime();
            long time2 = two.getTime();
            long diff ;
            if(time1<time2) {
                diff = time2 - time1;
            } else {
                diff = time1 - time2;
            }
            day = diff / (24 * 60 * 60 * 1000);
            hour = (diff / (60 * 60 * 1000) - day * 24);
        } catch (Exception e) {
            e.printStackTrace();
            LogUtils.d("test", e.getMessage());
        }
            return hour ;
    }


    /**
     * 两个时间相差距离多少小时(带上天)
     * @param one
     * @param two
     * @return String 返回值为：xx天xx小时xx分
     */
    public static long getDistanceTimeHourDay(Date one, Date two) {
        long day = 0;
        long hour = 0;
        try {
            long time1 = one.getTime();
            long time2 = two.getTime();
            long diff ;
            if(time1<time2) {
                diff = time2 - time1;
            } else {
                diff = time1 - time2;
            }
            day = diff / (24 * 60 * 60 * 1000);
            hour = (diff / (60 * 60 * 1000));
        } catch (Exception e) {
            e.printStackTrace();
            LogUtils.d("test", e.getMessage());
        }
        return hour ;
    }




    /**
     * 两个时间相差距离多少天多少小时多少分
     * @param one
     * @param two
     * @return String 返回值为：xx天xx小时xx分
     */
    public static long getDistanceTimemin(Date one, Date two) {
        long day = 0;
        long hour = 0;
        long min = 0;
        try {
            long time1 = one.getTime();
            long time2 = two.getTime();
            long diff ;
            if(time1<time2) {
                diff = time2 - time1;
            } else {
                diff = time1 - time2;
            }
            day = diff / (24 * 60 * 60 * 1000);
            hour = (diff / (60 * 60 * 1000) - day * 24);
            min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
        } catch (Exception e) {
            e.printStackTrace();
            LogUtils.d("test", e.getMessage());
        }
         return min ;
    }



    /**
     * 两个时间相差距离多少秒
     * @param one
     * @param two
     * @return String 返回值为：xx天xx小时xx分xx秒
     */
    public static long getDistanceTimeSecond(Date one, Date two) {

        long day = 0;
        long hour = 0;
        long min = 0;
        long sec = 0;
        try {

            long time1 = one.getTime();
            long time2 = two.getTime();
            long diff ;
            if(time1<time2) {
                diff = time2 - time1;
            } else {
                diff = time1 - time2;
            }
            day = diff / (24 * 60 * 60 * 1000);
            hour = (diff / (60 * 60 * 1000) - day * 24);
            min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
            sec = (diff/1000-day*24*60*60-hour*60*60-min*60);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return sec  ;

    }







    //返回总共多少分钟
    public static int getDistanceMin(Date one, Date two) {
        Integer min = 0;
        try {
            long time1 = one.getTime();
            long time2 = two.getTime();
            long time ;
            if(time1<time2) {
                time = time2 - time1;
            } else {
                time = time1 - time2;
            }
            long l = time / (60 * 1000);
            min = Integer.valueOf((int) l);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return min;
    }





    //返回总共多少分钟
    public static int getCencelDistanceMin(Date one, Date Two ) {
        Integer min = 0;
        try {
            long time1 = Two.getTime();
            long time2 = one.getTime();
            long time ;
            if(time1<time2) {
                time = time2 - time1;
            } else {
                time = time1 - time2;
            }
            long l = time / (60 * 1000);
            min = Integer.valueOf((int) l);
        } catch (Exception e) {
            e.printStackTrace();
        }


        return min;
    }



    //返回总共多少秒
    public static int getDistanceSecond(Date one, Date two) {
        Integer Second = 0;
        try {
            long time1 = one.getTime();
            long time2 = two.getTime();
            long time ;
            if(time1<time2) {
                time = time2 - time1;
            } else {
                time = time1 - time2;
            }
            long l = time / (60 * 1000) * 60;
            Second = Integer.valueOf((int) l);
        } catch (Exception e) {
            e.printStackTrace();
            LogUtils.d("test", e.getMessage());
        }
        return Second;
    }







    /**
     * 两个时间相差距离多少分
     * @param one
     * @param two
     * @return String 返回值为：xx分
     */
    public static String getDistanceTimeMin(Date one, Date two) {
        long min = 0;
        try {

            long time1 = one.getTime();
            long time2 = two.getTime();
            long diff ;
            if(time1<time2) {
                diff = time2 - time1;
            } else {
                diff = time1 - time2;
            }

            min = ((diff / (60 * 1000)) - (diff / (24 * 60 * 60 * 1000)) * 24 * 60 - (diff / (60 * 60 * 1000) - (diff / (24 * 60 * 60 * 1000)) * 24) * 60);
        } catch (Exception e) {
            e.printStackTrace();
            LogUtils.d("test", e.getMessage());
        }
        return min + "分" ;

    }




}
